﻿using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace GBricks
{
  public static class NullableBoolean
  {
    #region Methods

    public static T Switch<T>(this bool? value, T @true, T @false, T @null) {
      switch(value) {
      case true:
        return @true;
      case false:
        return @false;
      case null:
      default:
        return @null;
      }//switch
    }

    public static T Switch<T>(this bool? value, Func<T> @true, Func<T> @false, Func<T> @null) {
      Argument.NotNull(@true, "true");
      Argument.NotNull(@false, "false");
      Argument.NotNull(@null, "null");

      switch(value) {
      case true:
        return @true();
      case false:
        return @false();
      case null:
      default:
        return @null();
      }//switch
    }

    public static void Switch(this bool? value, Action @true, Action @false, Action @null) {
      Argument.NotNull(@true, "true");
      Argument.NotNull(@false, "false");
      Argument.NotNull(@null, "null");

      switch(value) {
      case true:
        @true();
        break;
      case false:
        @false();
        break;
      case null:
      default:
        @null();
        break;
      }//switch
    }

    #endregion Methods
  }
}
